package com.wuyou.simple;

import java.util.ArrayList;
import java.util.List;

/**
 * 2591. 将钱分给最多的儿童
 */
public class DistMoney {

    public static void main(String[] args) {
        int moeny=20,children=3;
        System.out.println(distMoney(moeny,  children));
        int[] arr=new int[5];
        List<String> list = new ArrayList<>();
        for(String i:list){

        }
    }
    public static int distMoney(int money, int children) {
        if(money<children)return -1;
        if(money-children<7){
            return 0;
        }
        int avg=money/children;
        int remain=money%children;
        if(avg==8&&remain==0){
            return children;
        }
        if(avg>8){
            return children-1;
        }
        int tempM=money,tempC=children-1,res=0;
        while(tempM>=8+tempC&&tempC>0){
            tempM-=8;
            tempC--;
            res++;
        }
        if(tempM==4&&tempC==0)res--;
        return res;
    }
}
